package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.entity.Auth;
import com.situ.feemanagement.pojo.query.AuthQuery;
import com.situ.feemanagement.service.IAuthService;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private IAuthService authService;

    @GetMapping("/list")
    public Result list(AuthQuery authQuery) {
        Map<String, Object> map = authService.selectByPage(authQuery);
        return Result.ok(map);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        authService.deleteById(id);
        return Result.ok("删除成功");
    }

    @DeleteMapping("/deleteAll/{ids}")
    public Result deleteAll(@PathVariable Integer[] ids) {
        authService.deleteAll(ids);
        return  Result.ok("删除成功");
    }

    @PostMapping("/add")
    public Result add(@RequestBody Auth auth) {
        authService.add(auth);
        return Result.ok("添加成功");
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Auth auth = authService.selectById(id);
        return Result.ok(auth);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Auth auth) {
        authService.Update(auth);
        return Result.ok("修改成功");
    }

    @PutMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Integer id, @PathVariable Integer status) {
        authService.updateStatus(id,status);
        return Result.ok("更新成功");
    }

    @GetMapping("/selectByRole")
    public Result selectByRole() {
        List<Auth> authList = authService.selectByRole();
        return Result.ok(authList);
    }
}
